package com.diandiansong.app.ui.index;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.LinearLayout;

import com.diandiansong.app.ui.base.BaseAct;
import com.just.agentweb.AgentWeb;

/**
 * 网页浏览器
 * 新闻
 */
public class Web extends BaseAct {

    static String mUrl;

    static String mTitle;
    static String mContent;


    public static void start(Context context, String url) {
        Intent starter = new Intent(context, Web.class);
        mUrl = url;
        context.startActivity(starter);
    }

    public static void start(Context context, String title, String content) {
        logger.d("start() called with: " + "context = [" + context + "], title = [" + title + "], content = [" + content + "]");
        mUrl = null;
        Intent starter = new Intent(context, Web.class);
        mTitle = title;
        mContent = content;
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initTitle("新闻详情");

        AgentWeb.PreAgentWeb preAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(mContentView, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .createAgentWeb()
                .ready();

        if (mUrl != null) {
            preAgentWeb
                    .go(mUrl);
        } else {
            initTitle(mTitle);
            AgentWeb agentWeb = preAgentWeb.go("127.0.0.1");
            WebView webView = agentWeb.getWebCreator().getWebView();
//            webView.loadData(mContent, "charset=UTF-8", null);
            webView.loadData(mContent, "text/html; charset=UTF-8", null);
        }
    }
}
